#pragma once
#include <bondlib/RealTimeDeal/IRealTimeDealModel.h>
#include <qbprotocol/include/SSFilters.h>

#include <map>
#include <string>

namespace detail {
enum kDealFilterType {
  kDealFilterTypeByAttention = 0,
  kDealFilterTypeBySearch,
  kDealFilterTypeByCondition,
  kDealFilterTypeBySearchInSSE,
  kDealFilterTypeByAttentionInSSE,
  kDealFilterTypeBySearchABS,
  kDealFilterTypeByConditionAndAttention
};
enum kConditionType {
  kConditionTypeAll,
  kConditionTypeCheck,
  kConditionTypeInvalid
};
class RealTimeDealFilter {
  /*
  共有三种过滤器:
  1.按照条件过滤
  2.按照关注债券过滤
  3.按照搜索过滤,又分为按照id匹配和按照key匹配

  */
  typedef std::map<std::string, int> ComKeyIndexMap;
  kDealFilterType m_filter_type;  // 三种匹配
  BLHCONDITION m_condition;
  kConditionType m_condition_type;
  int m_corp_id;
  std::string m_search_key;
  int m_search_type;
  std::string m_group_id;
  ComKeyIndexMap m_attend_map;
  bool m_bSSEFI;
  bool m_bABSFlag;

 public:
  RealTimeDealFilter();
  void SetCondition(const BLHCONDITION& blh, int corpid);
  void SetSearch(const std::string& key, int type, int corpid);
  void SetConditionAndSearch(const std::string& key, int type,
                             const BLHCONDITION& blh, int corpid);
  void SetAttention(const std::string& group, int corpid);
  void SetConditionAndAttention(const std::string& group,
                                const BLHCONDITION& blh, int corpid);
  void SetSSEFIFlag(bool bSSEFI);
  void SetABSBondFlag(bool bABS);
  bool IsDealPassed(const DealIndex& id, const void* record);

 protected:
  void BuildAttentionMap();
  int GetBondIndex(const char* bondKey, const char* listMarket);
};
}  // namespace detail
